package cn.mzy.config;

import cn.mzy.filter.ElapsedTimeFilter;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @Package: cn.mzy.filter
 * @ClassName: GatewayFilterConfig
 * @Date:2022/11/13 16:08
 * @Description:
 */
@Component
public class ElapsedTimeConfig {
    // 配置Filter作用于那个访问规则上
    @Bean
    public RouteLocator customerRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes().route(r -> r.path("/mzy/pay/**")
                //去掉1个前缀
                .filters(f -> f.stripPrefix(2)
                        .filter(new ElapsedTimeFilter())
                        .addResponseHeader("X-Response-test", "test"))
                .uri("lb://pay-server")
                .order(0)
                .id("test-RequestTimeFilter")
        ).build();
    }
}
